function createErpDailyReport() {
  // 在这里编写创建ERP日报的逻辑
  console.log('正在创建ERP日报...');
  // 实际操作可能涉及API调用、数据处理等
  //tmp 

  //记忆化存储erp，方便填写

  const par = {
    "ServiceOpportunityID": "",
    "ContactID": "",
    "ContactText": "",
    "CustomerClueID": "",
    "saleActivityCustomer": "",
    "saleActivityCustomerName": "",
    "JoinUserList": "",
    "MainBodyType": null,
    "WorkType": 7,
    "StatusID": "",
    "WorkLocation": 5,
    "WorkingHours": 8,
    "NeedAsyncWorkWechatSchedule": false,
    "LeaveType": 1,
    "date": "2024-05-28T00:00:00.000Z",
    "startTime": "2024-05-28 09:00",
    "endTime": "2024-05-28 18:30",
    "time": [
      "09:00",
      "18:30"
    ],
    "customer": "8a79193e-7ffb-e911-80f3-a2d3a0e0fa10",
    "CustomerName": "武汉众邦银行股份有限公司",
    "ProjectID": "c97e680c-59f5-421f-ba6d-575e3454f647",
    "DevelopmentType": 2,
    "EventType": 1,
    "SubjectID": "",
    "Subject": "05-27",
    "SubjectName": "",
    "ProductID": "F1F5ACF5-637A-4CC0-8AF4-AE2CF2A518DA",
    "ProductName": "",
    "TrainingProjectID": "",
    "BusinessKindID": "113B2E2E-9EE4-43DA-B257-F6F56E95387F",
    "IsDuringAllDay": true,
    "Body": "05-27",
    "BusinessTrip_Location": "",
    "ReimburseAmount": 0,
    "IsBusinessTrip": false,
    "HasMealAllowance": false,
    "ReimList": [],
    "PpmAppointmentInfo": {},
    "ProjectName": "",
    "ProductDevelopmentInfo": {
      "DevelopmentType": 2,
      "BusinessKindID": "113B2E2E-9EE4-43DA-B257-F6F56E95387F",
      "ProductID": "F1F5ACF5-637A-4CC0-8AF4-AE2CF2A518DA",
      "ProjectID": "c97e680c-59f5-421f-ba6d-575e3454f647"
    }
  }
  //par.date =


    url = 'https://erpgateway.cwoa.net:10240/net/api/AppointmentNew/SaveAppointment?t=1716804218929&customerActivityID=undefined'

  // 使用示例
  var access_token = getCookie('access_token');
  console.log(access_token);
  head = {
    'Accept': 'application/json, text/plain, */*',
    'Accept-Encoding': 'gzip, deflate, br, zstd',
    'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,en-GB;q=0.6',
    'Authorization': 'Bearer ' + access_token,
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Content-Length': '1181', // 需要替换为实际的JSON数据长度
    'Content-Type': 'application/json',
    'DNT': '1',
    'Host': 'erpgateway.cwoa.net:10240',
    'Origin': 'https://erpnew.cwoa.net',
    'Pragma': 'no-cache',
    'Referer': 'https://erpnew.cwoa.net/',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-site',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0',
    'sec-ch-ua': '"Microsoft Edge";v="125", "Chromium";v="125", "Not.A/Brand";v="24"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"'
  }

  fetch(url, {
    method: 'POST',
    headers: head,
    body: JSON.stringify(par)
  })
    .then(response => {
      if (!response.ok) {
        throw new Error('Network response was not ok');
      }
      return response.json();
    })
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));
}

document.addEventListener('DOMContentLoaded', function () {
  const myActionButton = document.getElementById('myActionButton');
  myActionButton.addEventListener('click', createErpDailyReport);


});


function getCookie(name) {
  var cookieArr = document.cookie.split('; '); // 将cookie字符串分割成多个条目
  for (var i = 0; i < cookieArr.length; i++) {
    var cookiePair = cookieArr[i].split('='); // 分割键值对
    /* 
        注意：由于JavaScript字符串不区分大小写，所以这里不需要进行大小写的转换。
        如果需要区分大小写，可以在比较name时使用toLowerCase()或toUpperCase()。
    */
    if (name == cookiePair[0]) { // 如果找到了匹配的键
      // 解码Cookie值并返回
      return decodeURIComponent(cookiePair[1]);
    }
  }
  // 如果没有找到匹配的键，返回null
  return null;
}

// 修改背景色
$('#update_bg_color').click(() => {
	executeScriptToCurrentTab('document.body.style.backgroundColor="red";')
});
